<?php
            
use app\model\Game; 


/**
 * Desc:
 * Time: 2021/3/10 1:24 下午
 */
class Index_Page extends PluginWebPage {

    function main($method) {
        global $_G,$_P,$_S,$_C;
        $themeid = $_P['themeid'];
        $page_index = max(1,intval($_P['page']));
        $page_size = 10;
        $page_start = ($page_index-1)*$page_size;
        $page_total = Game::getGameQuestionCount($themeid,'');
        $list = Game::getGameQuestionList($themeid,'',$page_start,$page_size);
        $pager = pagination($page_total,$page_start,$page_size);
        $ac = $method;
        $return_clicent = get_defined_vars();
return $this->view('/demo/question/question', $return_clicent);
    }

    function add()
    {
        return $this->post();
    }

    function edit()
    {
        return $this->post();
    }

    protected function post()
    {
        global $_G, $_P;
        $q_id = intval($_P['q_id']);
        $themeid = $_P['themeid'];
        if ($_G['ispost']) {
            $question = trim($_P['question']);
            $first = trim($_P['first']);
            $second = trim($_P['second']);
            $third = trim($_P['third']);
            $sure_method = $_P['sure_method'];
            $data = [
                'question'=>$question,
                'first'=>$first,
                'second'=>$second,
                'third'=>$third,
                'sure_method'=>$sure_method,
                'themeid'=>$themeid
            ];
            if (!$q_id){
                $res = Game::insertGameQuestion($data);
            }else{
                $where = ['q_id'=>$q_id];
                $res = Game::editGameQuestionByWhere($where,$data);
            }
            if (!$res){
                show_json(0);
            }else{
                show_json(1);
            }
        }
        if (!$q_id) {
            $return_clicent = get_defined_vars();
return $this->view('/demo/question/edit', $return_clicent);
        } else {
            $item = Game::getGameQuestionItemById($q_id);
            $return_clicent = get_defined_vars();
return $this->view('/demo/question/edit', $return_clicent);
        }
    }
}